//
//  JCContentCellView.swift
//  JCNewsForMac
//
//  Created by ifly on 16/8/18.
//  Copyright © 2018年 Ismail. All rights reserved.
//

import Cocoa

class JCContentCellView: NSView {
    
    
    
    private lazy var jcTitleLbl:NSTextField = {
        var jcTitleLbl = NSTextField()
        jcTitleLbl.isEditable = false
        jcTitleLbl.isBordered = false
        jcTitleLbl.font = NSFont.systemFont(ofSize: 16)
        jcTitleLbl.backgroundColor = NSColor.clear
        
        return jcTitleLbl
    }()
    
    private lazy var jcConLbl:NSTextField = {
        var jcConLbl = NSTextField()
        jcConLbl.isEditable = false
        jcConLbl.isBordered = false
        jcConLbl.font = NSFont.systemFont(ofSize: 14)
        jcConLbl.backgroundColor = NSColor.clear
        jcConLbl.textColor = NSColor.gray
        return jcConLbl
    }()
    
    private lazy var jcTimeLbl:NSTextField = {
        var jcTimeLbl = NSTextField()
        jcTimeLbl.isEditable = false
        jcTimeLbl.isBordered = false
        jcTimeLbl.font = NSFont.systemFont(ofSize: 13)
        jcTimeLbl.backgroundColor = NSColor.clear
        jcTimeLbl.alignment = .right
        return jcTimeLbl
    }()
    
    
    private lazy var jcComLbl:NSTextField = {
        var jcComLbl = NSTextField()
        jcComLbl.isEditable = false
        jcComLbl.isBordered = false
        jcComLbl.font = NSFont.systemFont(ofSize: 13)
        jcComLbl.backgroundColor = NSColor.clear
        return jcComLbl
    }()
    
    

    override func draw(_ dirtyRect: NSRect) {
        super.draw(dirtyRect)

        // Drawing code here.
    }
    
    
    override init(frame frameRect: NSRect) {
        super.init(frame: frameRect)
        
        self.addSubview(jcComLbl)
        self.addSubview(jcConLbl)
        self.addSubview(jcTimeLbl)
        self.addSubview(jcTitleLbl)
        setUI()
        
    }
    
    private func setUI(){
        
        jcTitleLbl.snp.makeConstraints { (make) in
            
            make.left.equalTo(self).offset(12)
            make.top.equalTo(self).offset(5)
            make.right.equalTo(self).offset(-10)
            make.height.equalTo(40)
        }
        
        
        jcConLbl.snp.makeConstraints { (make) in
            
            make.left.equalTo(self).offset(12)
            make.top.equalTo(jcTitleLbl.snp.bottom).offset(5)
            make.right.equalTo(self).offset(-10)
            make.height.equalTo(40)
        }
        
        
        jcComLbl.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(12)
            make.top.equalTo(jcConLbl.snp.bottom).offset(5)
//            make.right.equalTo(jcTimeLbl.snp.left).offset(10)
            make.height.equalTo(25)
        }
        
        jcTimeLbl.snp.makeConstraints { (make) in
            make.left.equalTo(jcComLbl.snp.right).offset(12)
            make.top.equalTo(jcConLbl.snp.bottom).offset(5)
            make.right.equalTo(self).offset(-10)
            make.size.equalTo(CGSize.init(width: 120, height: 25))
            
        }
        
    }
    
    func setData(_ data:JCContentModel) -> Void {
        
//        self.jcData = data
        
        jcTitleLbl.stringValue = data.ContentTitle
        jcConLbl.stringValue = data.Content
        jcComLbl.stringValue = data.CompanyName
        jcTimeLbl.stringValue = data.ReleaseTime
        
    }
    
    required init?(coder decoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
